package com.pearadmin.pro.modules.weixin;

import com.alibaba.fastjson.JSONObject;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.tools.core.OkHttpUtils;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.weixin.service.EnterpriseWinXinService;
import com.pearadmin.pro.modules.weixin.util.WXBizMsgCrypt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 企业微信登录 授权
 */
@Api(tags = {"EnterpriseWinXin"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"/EnterpriseWinXin")
@Slf4j
public class EnterpriseWinXinApi  extends BaseController {
    @Resource
    private EnterpriseWinXinService enterpriseWinXinService;

    @GetMapping("/getAuthorizeUrl")
    @ApiOperation(value = "网页授权链接")
    public Result<String> getAuthorizeUrl(@RequestParam String redirect_uri,@RequestParam String state){
        return success(enterpriseWinXinService.getAuthorizeUrl(redirect_uri,state));
    }

    @GetMapping("/getuserinfo")
    @ApiOperation(value = "获取访问用户身份")
    public Result<JSONObject> getAuthorizeUrl(@RequestParam String code){
        return success(enterpriseWinXinService.getUserInfo(code));
    }

    @GetMapping("/Login")
    @ApiOperation(value = "登录用户信息")
    public Result<JSONObject> Login(@RequestParam String userId){
        return enterpriseWinXinService.Login(userId);
    }

}
